<template>
	<view class="container">
		<view class="desc">
			<view class="textarea">
				<textarea v-model="FormData.field_value" placeholder="编辑备注" maxlength="150" @input="sum"></textarea>
				<view class="num">{{ fontNum }}/150</view>
			</view>
			<view class="btns">
				<button type="default" @click="back">返 回</button>
				<button type="primary" @click="submit">确 定</button>
			</view>
		</view>
	</view>
</template>

<script>
import api from '@/api/api';
export default {
	data() {
		return {
			type: '',
			fontNum: 0,
			FormData: {
				field_name: '',
				field_value: ''
			}
		};
	},
	onLoad(e) {
		this.type = e.type;
		this.FormData.field_value = e.value;
		if (e.type == 'rent') {
			this.FormData.field_name = 'rent_remark';
			this.FormData.rent_sn = e.sn;
		} else if (e.type == 'owner') {
			this.FormData.field_name = 'owner_remark';
			this.FormData.owner_id = e.id;
		} else if (e.type == 'room') {
			this.FormData.field_name = 'room_desc';
			this.FormData.room_id = e.id;
		} else if (e.type == 'billRent') {
			this.FormData.field_name = 'bill_desc';
			this.FormData.bill_id = e.id;
		} else if (e.type == 'billOwner') {
			this.FormData.field_name = 'bill_desc';
			this.FormData.bill_id = e.id;
		}
	},
	methods: {
		sum(e) {
			this.fontNum = e.detail.value.length;
		},
		success() {
			uni.showToast({
				title: '编辑成功'
			});
			setTimeout(() => {
				uni.hideToast();
				uni.navigateBack();
			}, 1000);
		},
		error() {
			uni.showToast({
				title: '内容更新失败',
				icon: 'error'
			});
		},
		back() {
			uni.navigateBack();
		},
		submit() {
			if (this.type == 'rent') {
				api.rentInfo(this.FormData).then((res) => {
					if (res.data.is_success) {
						this.success();
					} else {
						this.error();
					}
				});
			} else if (this.type == 'owner') {
				api.ownerInfo(this.FormData).then((res) => {
					if (res.data.is_success) {
						this.success();
					} else {
						this.error();
					}
				});
			} else if (this.type == 'room') {
				api.roomInfo(this.FormData).then((res) => {
					if (res.data.is_success) {
						this.success();
					} else {
						this.error();
					}
				});
			} else if (this.type == 'billRent') {
				api.billInfo(this.FormData).then((res) => {
					if (res.data.is_success) {
						this.success();
					} else {
						this.error();
					}
				});
			} else if (this.type == 'billOwner') {
				api.billOwnerInfo(this.FormData).then((res) => {
					if (res.data.is_success) {
						this.success();
					} else {
						this.error();
					}
				});
			}
		}
	}
};
</script>

<style lang="scss">
.desc {
	padding: 20rpx;
	.textarea {
		width: calc(100% - 40rpx);
		height: 390rpx;
		border-radius: 20rpx;
		padding: 20rpx;
		background: #fff;
		margin-bottom: 100rpx;
		position: relative;
		.num {
			position: absolute;
			bottom: 20rpx;
			right: 20rpx;
			font-size: 26rpx;
			color: $uni-base-color;
		}
		textarea {
			width: 100%;
			height: 100%;
			font-size: 30rpx;
			line-height: 50rpx;
		}
	}
	.btns {
		display: flex;
		justify-content: space-between;
		button {
			flex: 1;
			margin: 0 20rpx;
		}
	}
}
</style>
